// pages/city/city.js
let util = require("../../utils/util.js");
var baseImgUrl = util.baseImgUrl;
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    networkStatus: true,
    loadingStatus: false,//默认加载完成，true--正在加载中
    loadgif: util.imgUrl + "loading.gif",//加载gif图
    loading: util.imgUrl + "loading.png",
    none_network: util.imgUrl + "none_network.png",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getNetworkType({
      success: function (res) {
        var networkType = res.networkType;
        if (networkType == "none" || networkType == "unknown") {
          that.setData({
            networkStatus: false
          })
        } else {
          that.setData({
            networkStatus: true,
            
          })
        }
        console.log("***************city 获取网络情况******************");
        console.log(that.data.networkStatus);
      }, fail: function (err) {
        console.log("获取网络失败" + err);
        that.setData({
          networkStatus: false
        })
      }
    })
  },

  formSubmit:function(e){
    var username = e.detail.value.username;
    var contact = e.detail.value.contact;
    var cityname = e.detail.value.cityname;
    if (!username) {
      wx.showToast({
        title: '姓名不能为空',
        icon: 'none',
        duration: 1500
      })

    } else if (!contact) {
      wx.showToast({
        title: '联系方式不能为空',
        icon: 'none',
        duration: 1500
      })

    } else if (!cityname) {
      wx.showToast({
        title: '城市名称不能为空',
        icon: 'none',
        duration: 1500
      })

    }else{
      wx.request({
        url: util.chengshi,
        data: {
          openid: app.globalData.openid,
          username: username,
          contact: contact,
          address: cityname,
        },
        method: "POST",
        header: {
          "Content-Type": "application/x-www-form-urlencoded" //post
        },
        success: function (res) {
        },
        fail: function (err) {
        }
      })

      wx.showToast({
        title: '提交成功',
        icon: 'none',
        duration: 1500
      })

      setTimeout(function () {
        wx.navigateBack({
          delta: 1
        })
      }, 1500)
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
      var that=this;
    that.setData({
      
      loadingStatus: false
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})